package com.neusoft.neuiotms.dcam.fixed.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import org.hibernate.validator.constraints.Length;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.neusoft.bizcore.web.jpa.model.AbstractAuditModel;
import com.neusoft.bizcore.web.jpa.model.Comment;
import com.neusoft.neuiotms.dcam.fixed.model.enums.InventoryPlanStatus;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

@Getter
@Setter
@ToString
@Entity
@Table(name = "neuiot_inventory_plan")
@org.hibernate.annotations.Table(appliesTo = "neuiot_inventory_plan", comment = "盘点计划表")
public class InventoryPlan extends AbstractAuditModel {

    private static final long serialVersionUID = 1L;

    /** 盘点计划名 */
    @NotBlank(message = "盘点计划名称不能为空")
    @Length(max = 50, message = "盘点计划名称不能超过{max}位")
    @Column(length = 50)
    @Comment("varchar(50) NOT NULL COMMENT '名称'")
    private String name;

    /** 盘点计划编码 */
    @NotBlank(message = "盘点计划编码不能为空")
    @Length(max = 255, message = "盘点计划编码不能超过{max}位")
    @Column(length = 255, unique = true)
    @Comment("varchar(255) NOT NULL COMMENT '编码'")
    private String code;

    /** 创建人 */
    @NotNull(message = "创建人ID不能为空")
    @Comment("bigint(20) NOT NULL COMMENT '创建人ID'")
    private Long userId;

    /** 创建人名称 */
    @NotBlank(message = "创建人名称不能为空")
    @Length(max = 255, message = "创建人名称不能超过{max}位")
    @Column(length = 255)
    @Comment("varchar(255) NOT NULL COMMENT '创建人名称'")
    private String userName;

    /** 计划状态 */
    @Enumerated(EnumType.STRING)
    @NotNull(message = "计划状态不能为空")
    @Comment("varchar(255) NOT NULL COMMENT '计划状态'")
    private InventoryPlanStatus status = InventoryPlanStatus.created;

    /** 关联计划任务 */
    @OneToMany(mappedBy = "inventoryPlan", cascade = {CascadeType.REMOVE, CascadeType.MERGE }, fetch = FetchType.EAGER)
    @LazyCollection(LazyCollectionOption.FALSE)
    List<InventoryDuty> dutyItems = new ArrayList<>();

    /** 开始日期 */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '开始日期'")
    private Date startDate;

    /** 结束日期 */
    @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8")
    @Comment("datetime NULL DEFAULT NULL COMMENT '结束日期'")
    private Date endDate;

    /** 盘点说明 */
    @Length(max = 255, message = "盘点说明不能超过{max}位")
    @Column(length = 255)
    @Comment("varchar(255) COMMENT '说明'")
    private String remarks;
}
